// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   OrderDetailProcessor.java

package com.boci.clientapp.orderstatus.processor;

import com.boci.clientapp.orderstatus.vo.FilledOrderVO;
import com.boci.clientapp.orderstatus.vo.OrderDetailVO;
import com.boci.common.processor.AbstractResponseProcessor;
import com.boci.common.vo.ResponseVO;
import java.util.ArrayList;
import org.w3c.dom.*;

public class OrderDetailProcessor extends AbstractResponseProcessor
{

    public OrderDetailProcessor(String pXML, String pReqType)
        throws Exception
    {
        super(pXML, pReqType, "ORDER_STATUS.ERROR_");
    }

    public ResponseVO processXML()
        throws Exception
    {
        strReqType = getReqType();
        strRtnCode = getReturnCode();
        String strProductLine = getNodeValue("PRODUCT_LINE");
        String strSymbol = getNodeValue("SYMBOL");
        String strName = getNodeValue("NAME");
        String strName_chi = getNodeValue("NAME_CHI");
        String strName_chs = getNodeValue("NAME_CHS");
        String strOrderDuration = getNodeValue("ORDER_DURATION");
        String strOriginalQuantity = getNodeValue("ORIGINAL_QUANTITY");
        String strFilledQuantity = getNodeValue("FILLED_QUANTITY");
        String strOutstandingQuantity = getNodeValue("OUTSTANDING_QUANTITY");
        String strReducedQuantity = getNodeValue("REDUCED_QUANTITY");
        String strCanceledQuantity = getNodeValue("CANCELED_QUANTITY");
        String strBuyOrSell = getNodeValue("BUY_OR_SELL");
        String strPrice = getNodeValue("PRICE");
        String strCurrency = getNodeValue("CURRENCY");
        String strOrderTye = getNodeValue("ORDER_TYPE");
        String strOrderQualifier = getNodeValue("ORDER_QUALIFIER");
        String strOrderStatus = getNodeValue("ORDER_STATUS");
        String strPlacementDate = getNodeValue("PLACEMENT_DATE");
        String strOrderQuantity = getNodeValue("ORDER_QUANTITY");
        OrderDetailVO orderDetailVO = new OrderDetailVO(getReqType(), getReturnCode());
        orderDetailVO.setProductLine(strProductLine);
        orderDetailVO.setSymbol(strSymbol);
        orderDetailVO.setName(strName);
        orderDetailVO.setName_chi(strName_chi);
        orderDetailVO.setName_chs(strName_chs);
        orderDetailVO.setOrderDuration(strOrderDuration);
        orderDetailVO.setOriginalQuantity(strOriginalQuantity);
        orderDetailVO.setFilledQuantity(strFilledQuantity);
        orderDetailVO.setOutstandingQuantity(strOutstandingQuantity);
        orderDetailVO.setReducedQuantity(strReducedQuantity);
        orderDetailVO.setCanceledQuantity(strCanceledQuantity);
        orderDetailVO.setBuyOrSell(strBuyOrSell);
        orderDetailVO.setPrice(strPrice);
        orderDetailVO.setCurrency(strCurrency);
        orderDetailVO.setOrderType(strOrderTye);
        orderDetailVO.setOrderQualifier(strOrderQualifier);
        orderDetailVO.setOrderStatus(strOrderStatus);
        orderDetailVO.setPlacementDate(strPlacementDate);
        orderDetailVO.setOrderQuantity(strOrderQuantity);
        NodeList orderList = resultDocument.getElementsByTagName("ORDER");
        Element element = (Element)orderList.item(0);
        String strOrderId = getAttrValue(element, "ORDER_ID");
        String strAllowCancel = getAttrValue(element, "ALLOW_CANCEL");
        String strAllowChange = getAttrValue(element, "ALLOW_CHANGE");
        boolean allowCancelFlag;
        if(strAllowCancel != null && "TRUE".equals(strAllowCancel))
            allowCancelFlag = true;
        else
            allowCancelFlag = false;
        strAllowChange = getAttrValue(element, "ALLOW_CHANGE");
        boolean allowChangeFlag;
        if(strAllowChange != null && "TRUE".equals(strAllowChange))
            allowChangeFlag = true;
        else
            allowChangeFlag = false;
        orderDetailVO.setOrderId(strOrderId);
        orderDetailVO.setAllowCancel(allowCancelFlag);
        orderDetailVO.setAllowChange(allowChangeFlag);
        NodeList filledList = resultDocument.getElementsByTagName("FILLED_ORDER");
        ArrayList filledOrderList = transformVOList(filledList);
        if(filledList.getLength() > 0)
        {
            filledOrderList = transformVOList(filledList);
            orderDetailVO.setFilledOrderList(filledOrderList);
        }
        return orderDetailVO;
    }

    public ArrayList transformVOList(NodeList pNodeList)
    {
        int nodeLength = pNodeList.getLength();
        ArrayList list = new ArrayList();
        for(int i = 0; i < nodeLength; i++)
        {
            FilledOrderVO filledOrderVO = new FilledOrderVO(strReqType, strRtnCode);
            Element element = (Element)pNodeList.item(i);
            String strFilledQuantity = getNodeValue(element, "FILLED_QUANTITY");
            String strFilledPrice = getNodeValue(element, "FILLED_PRICE");
            filledOrderVO.setFilledQuantity(strFilledQuantity);
            filledOrderVO.setFilledPrice(strFilledPrice);
            list.add(filledOrderVO);
        }

        return list;
    }

    String strRtnCode;
    String strReqType;
}
